﻿using HookupAppForm.Dto;
using HookupAppForm.MyUserControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HookupAppForm
{
    public partial class FormTool : Form
    {
        private HKP_ToolDto Item { get; set; }
        private HKP_ToolSysReqDto ItemSysReq { get; set; }
        private readonly string url = "api/services/app/HKP_Tool/";
        private readonly string urlSysReq = "api/services/app/HKP_ToolSysReq/";
        private readonly string urlBlock = "api/services/app/HKP_Block/";

        private APIClient Client { get; set; }
        //大系统
        ItemsDto<HKP_CategoryDto> listSystemType;
        ItemsDto<HKP_SystemDto> res1;
        FormMain mainForm;
        public FormTool(HKP_ToolDto _item, APIClient _client,FormMain _formMain)
        {           
            InitializeComponent();
            this.Item = _item;
            Client = _client;
            mainForm = _formMain;
        }

        private void SaveToolStripButton_Click(object sender, EventArgs e)
        {
            if (Item != null)
            {
                if(Item.songshen == true)
                {
                    Utils.SysMsg("机台已送审，不允许修改，可撤回之后修改！");
                    return;
                }
            }
         

            string[] str = mainForm.user[0].RoleNames;
            int a = str.Count(p => p == "ADMIN" || p == "DEVICEMANAGER");
            if (a <= 0)
            {
                Utils.SysMsg("对不起！权限不足，请联系管理员！");
                return;
            }
            if (Item == null)
            {
                CreateTool();
            }
            else
            {
                dataGridViewM.EndEdit();
                Item.ToolId = ToolIdBox.Text.Trim();
                Item.ToolName = ToolNameBox.Text.Trim();
                Item.ToolModel = ToolModelBox.Text.Trim();
                Item.VendorNo = VendorNoBox.Text.Trim();
                Item.CateId = Convert.ToInt32(ucDrpToolCls.selectedValue);
                Item.Length = LengthUpDown.Value;
                Item.Width = WidthUpDown.Value;
                Item.Height = HeightUpDown.Value;
                Item.SystemRequired = "0";
                Item.Version = VersionBox.Text.Trim();
                Item.Weight = Convert.ToDecimal(numWeight.Text.Trim());
                Item.Behind = BehindUpDown.Value;
                Item.Front = FrontUpDown.Value;
                Item.Left = LeftUpDown.Value;
                Item.Right = RightUpDown.Value;
                Item.ShockSource = ShockSourceBox.Text;
                Item.WaterNeed = WaterNeedBox.Text;
                Item.PedestalNeed = PedestalNeedBox.Text;
                Item.Remark = RemarkBox.Text.Trim();
                Item.Power = numPower.Value;
                Item.Pressure = numPressure.Value;
                Item.FlowPeak = numFlowPeak.Value;
                Item.OutSize = ucDrpOutSize.selectedText;
                Item.NeedBellow = cBoxNeedBellow.Checked;
                Item.NeedBreaker = cBoxNeedBreaker.Checked;
                Item.NeedFilter = cBoxNeedFilter.Checked;
                Item.NeedFlowmeter = cBoxNeedFlowmeter.Checked;
                Item.NeedPreGauge = cBoxNeedPreGauge.Checked;
                Item.NeedTap = cBoxNeedTap.Checked;
                Item.NeedTrap = cBoxNeedTrap.Checked;
                Item.NeedValve = cBoxNeedValve.Checked;
                Item.Voltage = numVoltage.Value <= 0 ? 220 : numVoltage.Value;
                Item.ElcCurrent = Item.Power / Item.Voltage;
                Item.TemperatureWRTMin = numTemperatureWRTMin.Value;
                Item.TemperatureWRTMax = numTemperatureWRTMax.Value;
                Item.X = numX.Value;
                Item.Y = numY.Value;
                Item.Building = ucDpdBuilding.selectedText;
                Item.Floor = ucDpdFloor.selectedText;
                Item.EquipmentID = txtEqMentID.Text.Trim();
                Item.BlockId = Convert.ToInt32(comBlockID.SelectedValue);
                Item.BlockName = comBlockID.Text;
                string jsons = JsonConvert.SerializeObject(Item);
                var result = Client.Put(url + "Update", jsons);
                if (Utils.ExceptionHandler(result) == null)
                {
                    Utils.SysMsg("编辑成功！");
                    DialogResult = DialogResult.OK;
                }
            }
        }

        private void CreateTool()
        {
            dataGridViewM.EndEdit();

            CreateHKP_ToolDto dto = new CreateHKP_ToolDto();
            dto.ToolId = ToolIdBox.Text.Trim();
            dto.ToolName = ToolNameBox.Text.Trim();
            dto.ToolModel = ToolModelBox.Text.Trim();
            dto.VendorNo = VendorNoBox.Text.Trim();
            dto.CateId = Convert.ToInt32(ucDrpToolCls.selectedValue);
            dto.Length = LengthUpDown.Value;
            dto.Width = WidthUpDown.Value;
            dto.Height = HeightUpDown.Value;
            dto.SystemRequired = "0";
            dto.Version = VersionBox.Text.Trim();
            dto.Weight = Convert.ToDecimal(numWeight.Text.Trim());
            dto.Behind = BehindUpDown.Value;
            dto.Front = FrontUpDown.Value;
            dto.Left = LeftUpDown.Value;
            dto.Right = RightUpDown.Value;
            dto.ShockSource = ShockSourceBox.Text;
            dto.WaterNeed = WaterNeedBox.Text;
            dto.PedestalNeed = PedestalNeedBox.Text;
            dto.Remark = RemarkBox.Text.Trim();
            dto.Power = numPower.Value;
            dto.Pressure = numPressure.Value;
            dto.FlowPeak = numFlowPeak.Value;
            dto.OutSize = textOutSize.Text.Trim();//ucDrpOutSize.selectedText;
            dto.NeedBellow = cBoxNeedBellow.Checked;
            dto.NeedBreaker = cBoxNeedBreaker.Checked;
            dto.NeedFilter = cBoxNeedFilter.Checked;
            dto.NeedFlowmeter = cBoxNeedFlowmeter.Checked;
            dto.NeedPreGauge = cBoxNeedPreGauge.Checked;
            dto.NeedTap = cBoxNeedTap.Checked;
            dto.NeedTrap = cBoxNeedTrap.Checked;
            dto.NeedValve = cBoxNeedValve.Checked;
            dto.Voltage = numVoltage.Value <= 0 ? 220 : numVoltage.Value;
            dto.ElcCurrent = dto.Power / dto.Voltage;            
            dto.TemperatureWRTMin = numTemperatureWRTMin.Value;
            dto.TemperatureWRTMax = numTemperatureWRTMax.Value;
            dto.X = numX.Value;
            dto.Y = numY.Value;
            dto.Building = ucDpdBuilding.selectedText;
            dto.Floor = ucDpdFloor.selectedText;
            dto.EquipmentID = txtEqMentID.Text.Trim();
            dto.BlockId = Convert.ToInt32(comBlockID.SelectedValue);
            dto.BlockName = comBlockID.Text;
            string jsons = JsonConvert.SerializeObject(dto);
            var result = Client.Post(url + "Create", jsons);
            if (Utils.ExceptionHandler(result) == null)
            {
                Utils.SysMsg("新建成功！");
                var resp = Utils.SuccessHandler(result);
                Item = JsonConvert.DeserializeObject<HKP_ToolDto>(resp.ToString());
                DialogResult = DialogResult.OK;
                buttonAddConn.Enabled = true;
            }
        }

        private void FormEdit_Load(object sender, EventArgs e)
        {
            //系统类型
            string url = string.Format("api/services/app/HKP_System/GetList");
            var result = Client.Get(url);
            ItemsDto<HKP_SystemDto> dto = JsonConvert.DeserializeObject<ItemsDto<HKP_SystemDto>>(result);
            cBoxSysNo.DataSource = dto?.result?.items?.ToList();
            cBoxSysNo.DisplayMember = "SysNo";
            cBoxSysNo.ValueMember = "SysNo";
            cBoxSysNo.SelectedIndex = -1;
            //大系统数据加载
            GetSystem("System", 0);

            ucDrpToolCls.Init("Tool", Client.RemoteHost);
            //ucDrpOutSize.Init("尺寸", Client.RemoteHost);
            //ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "kw");
            //ucDrpFlowUnit.Init("流量", Client.RemoteHost, 0, "CMH");
            //ucDrpPressUnit.Init("压力单位", Client.RemoteHost, 0, "MPa");
            //ucDrpOutSizeUnit.Init("尺寸单位", Client.RemoteHost, 0, "in");
            ucDrpOutType.Init("接点类型", Client.RemoteHost);
            ucDpdBuilding.Init("Building", Client.RemoteHost);
            ucDpdBuilding.selectedChangeEvent += new UserControlDropdown.SelectedChangeDelegate(UcDpdBuildingSelectedChange);
            ucDpdFloor.selectedChangeEvent += new UserControlDropdown.SelectedChangeDelegate(ucDpdFloorSelectedChange);

            if (Item != null)
            {
                ToolIdBox.Text = Item.ToolId;
                ToolNameBox.Text = Item.ToolName;
                ToolModelBox.Text = Item.ToolModel;
                VendorNoBox.Text = Item.VendorNo;
                LengthUpDown.Value = Item.Length;
                WidthUpDown.Value = Item.Width;
                HeightUpDown.Value = Item.Height;
                numWeight.Value = Item.Weight;
                BehindUpDown.Value = Item.Behind;
                FrontUpDown.Value = Item.Front;
                LeftUpDown.Value = Item.Left;
                RightUpDown.Value = Item.Right;
                ShockSourceBox.Text = Item.ShockSource;
                WaterNeedBox.Text = Item.WaterNeed;
                PedestalNeedBox.Text = Item.PedestalNeed;
                RemarkBox.Text = Item.Remark;
                VersionBox.Text = Item.Version;                
                ucDrpToolCls.SetValue(Item.CateId);
                ucDrpOutSize.SetText(Item.OutSize);                
                numVoltage.Value = Item.Voltage;
                GetToolSysReq(Item.Id);
                buttonAddConn.Enabled = true;
                numX.Value = Item.X;
                numY.Value = Item.Y;
                txtEqMentID.Text = Item.EquipmentID;
                ucDpdBuilding.SetText(Item.Building);
                ucDpdFloor.SetText(Item.Floor);
                //区域赋值
                string url2 = string.Format(urlBlock + "Get?id={0}", Item.BlockId);
                var result2 = Client.Get(url2);
                SuccessAccountBlockID dto2 = JsonConvert.DeserializeObject<SuccessAccountBlockID>(result2);
                if (dto2.success==true)
                {
                    List<HKP_BlockDto> list = new List<HKP_BlockDto>();
                    list.Add(dto2.result);

                    comBlockID.DataSource = null;
                    comBlockID.DisplayMember = "blockName";
                    comBlockID.ValueMember = "id";
                    comBlockID.DataSource = list;
                    //comBlockID.SelectedItem = dto2.result;
                }


            }
            

            
        }
        private void UcDpdBuildingSelectedChange(object sender, EventArgs e)
        {
            ucDpdFloor.Init("Building", Client.RemoteHost, Convert.ToInt32(ucDpdBuilding.selectedValue));
        }
        private void ucDpdFloorSelectedChange(object sender,EventArgs e)
        {
            string url = string.Format(urlBlock + "GetList?building={0}&floor={1}&skipCount=0&maxResultCount=9999", ucDpdBuilding.selectedText,ucDpdFloor.selectedText);
            var result = Client.Get(url);
            ItemsDto<HKP_BlockDto> dto = JsonConvert.DeserializeObject<ItemsDto<HKP_BlockDto>>(result);
            if (dto?.result?.items != null)
            {
                comBlockID.DisplayMember = "blockName";
                comBlockID.ValueMember = "id";
                comBlockID.DataSource = dto.result.items;
            }

        }

        private void GetToolSysReq(string toolId)
        {
            string url = string.Format(urlSysReq + "GetList?id={0}", toolId);
            var result = Client.Get(url);
            ItemsDto<HKP_ToolSysReqDto> dto = JsonConvert.DeserializeObject<ItemsDto<HKP_ToolSysReqDto>>(result);
            dataGridViewM.DataSource = dto.result.items;
            FromSetting[] fromSettings = new FromSetting[15];
            fromSettings[2] = new FromSetting { FieldDisplay = "所需系统",FieldDisplayIndex=1 };
            fromSettings[3] = new FromSetting { FieldDisplay = "接点编号", FieldDisplayIndex = 2 };
            fromSettings[6] = new FromSetting { FieldDisplay = "流量/容量", FieldDisplayIndex = 3 };
            fromSettings[7] = new FromSetting { FieldDisplay = "流量单位/容量单位", FieldDisplayIndex = 4 };
            fromSettings[8] = new FromSetting { FieldDisplay = "压力大小/设备路断", FieldDisplayIndex = 5 };
            fromSettings[9] = new FromSetting { FieldDisplay = "单位", FieldDisplayIndex = 6 };
            fromSettings[10] = new FromSetting { FieldDisplay = "管径大小/电压（V）", FieldDisplayIndex = 7 };
            fromSettings[11] = new FromSetting { FieldDisplay = "管径单位/电源种类", FieldDisplayIndex = 8 };
            fromSettings[12] = new FromSetting { FieldDisplay = "最低排水温度", FieldDisplayIndex = 9 };
            fromSettings[13] = new FromSetting { FieldDisplay = "最高排水温度", FieldDisplayIndex = 10 };
            fromSettings[4] = new FromSetting { FieldDisplay = "功率", FieldDisplayIndex = 11 };
            fromSettings[5] = new FromSetting { FieldDisplay = "单位", FieldDisplayIndex = 12 };
            fromSettings[14] = new FromSetting { FieldDisplay = "接口类型", FieldDisplayIndex = 13 };
            Utils.SetHeader(dataGridViewM, fromSettings);
        }
        private void DelToolStripButton_Click(object sender, EventArgs e)
        {
            if (Item != null)
            {
                if (Item.songshen == true)
                {
                    Utils.SysMsg("机台已送审，不允许修改，可撤回之后修改！");
                    return;
                }
            }

            string[] str1 = mainForm.user[0].RoleNames;
            int a = str1.Count(p => p == "ADMIN" || p == "DEVICEMANAGER");
            if (a <= 0)
            {
                Utils.SysMsg("对不起！权限不足，请联系管理员！");
                return;
            }

            if (MessageBox.Show("确定删除？", "系统", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                var items = dataGridViewM.DataSource as HKP_ToolSysReqDto[];
                if (items.Length > 0)
                {
                    Utils.SysMsg("请先删除接口数据", MessageBoxIcon.Warning);
                    return;
                }
                if (Item != null)
                {
                    string act = string.Format(url + "Delete?Id={0}", Item.Id);
                    string result = Client.Delete(act);
                    if (Utils.ExceptionHandler(result) == null)
                    {
                        NewToolStripButton_Click(sender, e);
                    }
                    buttonAddConn.Enabled = false;
                    buttonSaveConn.Enabled = false;
                    this.DialogResult = DialogResult.OK;
                }
            }
        }

        private void NewToolStripButton_Click(object sender, EventArgs e)
        { 
            string[] str = mainForm.user[0].RoleNames;
            int a = str.Count(p => p == "ADMIN" || p == "DEVICEMANAGER");
            if (a <= 0)
            {
                Utils.SysMsg("对不起！权限不足，请联系管理员！");
                return;
            }
            ToolIdBox.Text = "";
            ToolNameBox.Text = "";
            ToolModelBox.Text = "";
            VendorNoBox.Text = "";
            LengthUpDown.Value = 0;
            WidthUpDown.Value = 0;
            HeightUpDown.Value = 0;
            numWeight.Value = 0;
            BehindUpDown.Value = 0;
            FrontUpDown.Value = 0;
            LeftUpDown.Value = 0;
            RightUpDown.Value = 0;
            ShockSourceBox.Text = "";
            WaterNeedBox.Text = "";
            PedestalNeedBox.Text = "";
            RemarkBox.Text = "";
            numX.Value = 0;
            numY.Value = 0;
            Item = null;
            dataGridViewM.DataSource = null;
        }

        private void CopyToolStripButton_Click(object sender, EventArgs e)
        {
            string[] str = mainForm.user[0].RoleNames;
            int a = str.Count(p => p == "ADMIN" || p == "DEVICEMANAGER");
            if (a <= 0)
            {
                Utils.SysMsg("对不起！权限不足，请联系管理员！");
                return;
            }
            if (Item != null)
            {
                string act = url + "Create";
                Item.ToolName += " Copy";
                Item.ToolId += "Copy";
                string jsons = JsonConvert.SerializeObject(Item);
                string result = Client.Post(act, jsons);
                if (Utils.ExceptionHandler(result) == null)
                {
                    Utils.SysMsg("复制成功！", MessageBoxIcon.Information);
                    var resp = Utils.SuccessHandler(result);
                    Item = JsonConvert.DeserializeObject<HKP_ToolDto>(resp.ToString());
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void ButtonAddConn_Click(object sender, EventArgs e)
        {
      

            string[] str1 = mainForm.user[0].RoleNames;
            int a1 = str1.Count(p => p == "ADMIN" || p == "DEVICEMANAGER");
            if (a1 <= 0)
            {
                Utils.SysMsg("对不起！权限不足，请联系管理员！");
                return;
            }

            if (Item != null)
            {
                if (Item.songshen == true)
                {
                    Utils.SysMsg("机台已送审，不允许修改，可撤回之后修改！");
                    return;
                }
            }
            var sysNo = cBoxSysNo.SelectedItem as HKP_SystemDto;
            var systemType = cBoxSystemType.SelectedItem as HKP_CategoryDto;
            if (Item == null)
            {
                Utils.SysMsg("请先打开机台！", MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(textBoxName.Text))
            {
                Utils.SysMsg("请输入接口名！", MessageBoxIcon.Warning);
                return;
            }
            if (systemType==null)
            {
                Utils.SysMsg("请选择主系统！", MessageBoxIcon.Warning);
                return;
            }
            if (sysNo == null)
            {
                Utils.SysMsg("请选择详细", MessageBoxIcon.Warning);
                return;
            }
            if (string.IsNullOrEmpty(textOutSize.Text.Trim()))
            {
                Utils.SysMsg("对不起，接口尺寸不能为空！", MessageBoxIcon.Warning);
                return;
            }


            if (systemType.CateName == "PE")
            {
                string[] str =  mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > -100 )
                    {
                        Utils.SysMsg("对不起！负压只能输入-100到-200之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < -200
                    if (numPressure.Value < -200)
                    {
                        Utils.SysMsg("对不起！负压只能输入-100到-200之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                }

            }
            if (systemType.CateName == "PV")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > -630 )
                    {
                        Utils.SysMsg("对不起！PV负压只能输入-640之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < -650
                    if (numPressure.Value < -650)
                    {
                        Utils.SysMsg("对不起！PV负压只能输入-640之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }

                }
            }
            if(systemType.CateName == "PB_PP")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > 7 )
                    {
                        Utils.SysMsg("对不起！PB_PP只能输入5-7之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < 5
                    if (numPressure.Value < 5)
                    {
                        Utils.SysMsg("对不起！PB_PP只能输入5-7之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }

                }
            }
            if (systemType.CateName == "PC")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > 3)
                    {
                        Utils.SysMsg("对不起！PC只能输入2-3之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    // && numPressure.Value < 3
                    if (numPressure.Value < 2)
                    {
                        Utils.SysMsg("对不起！PC只能输入2-3之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            if (systemType.CateName == "PS")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value >7 )
                    {
                        Utils.SysMsg("对不起！PC只能输入3,5,7 需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < 7
                    if (numPressure.Value < 3)
                    {
                        Utils.SysMsg("对不起！PC只能输入3,5,7 需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                }
            }

            CreateHKP_ToolSysReqDto dto = new CreateHKP_ToolSysReqDto();
            dto.FlowPeak = numFlowPeak.Value;
            dto.FlowOper = numFlowOpr.Value;
            dto.FlowAvg = numFlowAvg.Value;
            dto.FlowUnit = ucDrpFlowUnit.selectedText;
            dto.OutSize = textOutSize.Text.Trim(); //ucDrpOutSize.selectedText;
            dto.OutSizeUnit = ucDrpOutSizeUnit.selectedText;
            dto.Power = numPower.Value;
            dto.PowerUnit = ucDrpPowerUnit.selectedText;
            dto.Pressure = numPressure.Value;
            dto.PressureUnit = ucDrpPressUnit.selectedText;
            dto.SysNo = cBoxSysNo.SelectedValue.ToString();
            dto.ToolId = Item.Id;//Item.ToolId;
            dto.TemperatureWRTMax = numTemperatureWRTMax.Value;
            dto.TemperatureWRTMin = numTemperatureWRTMin.Value;
            dto.OutType = ucDrpOutType.selectedText;
            dto.Name = textBoxName.Text;
            dto.NeedBellow = cBoxNeedBellow.Checked;
            dto.NeedBreaker = cBoxNeedBreaker.Checked;
            dto.NeedFilter = cBoxNeedFilter.Checked;
            dto.NeedFlowmeter = cBoxNeedFlowmeter.Checked;
            dto.NeedPreGauge = cBoxNeedPreGauge.Checked;
            dto.NeedTap = cBoxNeedTap.Checked;
            dto.NeedTrap = cBoxNeedTrap.Checked;
            dto.NeedValve = cBoxNeedValve.Checked;
            dto.EquipmentID = txtEqMentID.Text;
            dto.Wenduji = cBoxWenduji.Checked;//新增温度计
            dto.SystemType = cBoxSystemType.SelectedValue.ToString();//新增大系统
            string jsons = JsonConvert.SerializeObject(dto);
            var result = Client.Post(urlSysReq + "Create", jsons);
            if (Utils.ExceptionHandler(result) == null)
            {
                Utils.SysMsg("新建成功！");
                var resp = Utils.SuccessHandler(result);
                ItemSysReq = JsonConvert.DeserializeObject<HKP_ToolSysReqDto>(resp.ToString());
                GetToolSysReq(Item.Id);
                buttonSaveConn.Enabled = true;
            }
        }

        private void ButtonSaveConn_Click(object sender, EventArgs e)
        {
            string[] str1 = mainForm.user[0].RoleNames;
            int a1 = str1.Count(p => p == "ADMIN" || p == "DEVICEMANAGER");
            if (a1 <= 0)
            {
                Utils.SysMsg("对不起！权限不足，请联系管理员！");
                return;
            }
            if (Item != null)
            {
                if (Item.songshen == true)
                {
                    Utils.SysMsg("机台已送审，不允许修改，可撤回之后修改！");
                    return;
                }
            }

            var sysNo = cBoxSysNo.SelectedItem as HKP_SystemDto;
            var systemType = cBoxSystemType.SelectedItem as HKP_CategoryDto;

            if (string.IsNullOrEmpty(textOutSize.Text.Trim()))
            {
                Utils.SysMsg("对不起，接口尺寸不能为空！", MessageBoxIcon.Warning);
                return;
            }
            if (systemType == null)
            {
                Utils.SysMsg("请选择主系统！", MessageBoxIcon.Warning);
                return;
            }
            if (sysNo == null)
            {
                Utils.SysMsg("请选择详细", MessageBoxIcon.Warning);
                return;
            }
            if (systemType.CateName == "PE")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > -100)
                    {
                        Utils.SysMsg("对不起！负压只能输入-100到-200之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < -200
                    if (numPressure.Value < -200)
                    {
                        Utils.SysMsg("对不起！负压只能输入-100到-200之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                }

            }
            if (systemType.CateName == "PV")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > -630)
                    {
                        Utils.SysMsg("对不起！PV负压只能输入-640之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < -650
                    if (numPressure.Value < -650)
                    {
                        Utils.SysMsg("对不起！PV负压只能输入-640之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }

                }
            }
            if (systemType.CateName == "PB_PP")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > 7)
                    {
                        Utils.SysMsg("对不起！PB_PP只能输入5-7之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < 5
                    if (numPressure.Value < 5)
                    {
                        Utils.SysMsg("对不起！PB_PP只能输入5-7之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }

                }
            }
            if (systemType.CateName == "PC")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > 3)
                    {
                        Utils.SysMsg("对不起！PC只能输入2-3之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    // && numPressure.Value < 3
                    if (numPressure.Value < 2)
                    {
                        Utils.SysMsg("对不起！PC只能输入2-3之间，需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            if (systemType.CateName == "PS")
            {
                string[] str = mainForm.user[0].RoleNames;
                int a = str.Count(p => p == "ADMIN");
                if (a <= 0)
                {
                    if (numPressure.Value > 7)
                    {
                        Utils.SysMsg("对不起！PC只能输入3,5,7 需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                    //&& numPressure.Value < 7
                    if (numPressure.Value < 3)
                    {
                        Utils.SysMsg("对不起！PC只能输入3,5,7 需要输入其他请联系管理员！", MessageBoxIcon.Warning);
                        return;
                    }
                }
            }

            if (Item == null)
            {
                Utils.SysMsg("请先打开机台！", MessageBoxIcon.Warning);
                return;
            }
            if (ItemSysReq == null)
            {
                Utils.SysMsg("请先添加参数！", MessageBoxIcon.Warning);
                return;
            }
            ItemSysReq.FlowPeak = numFlowPeak.Value;
            ItemSysReq.FlowAvg = numFlowAvg.Value;
            ItemSysReq.FlowOper = numFlowOpr.Value;
            ItemSysReq.FlowUnit = ucDrpFlowUnit.selectedText;
            ItemSysReq.OutSize = textOutSize.Text.Trim();//ucDrpOutSize.selectedText;
            ItemSysReq.OutSizeUnit = ucDrpOutSizeUnit.selectedText;
            ItemSysReq.Power = numPower.Value;
            ItemSysReq.PowerUnit = ucDrpPowerUnit.selectedText;
            ItemSysReq.Pressure = numPressure.Value;
            ItemSysReq.PressureUnit = ucDrpPressUnit.selectedText;
            ItemSysReq.SysNo = cBoxSysNo.SelectedValue.ToString();
            ItemSysReq.ToolId = Item.Id;//Item.ToolId;
            ItemSysReq.TemperatureWRTMax = numTemperatureWRTMax.Value;
            ItemSysReq.TemperatureWRTMin = numTemperatureWRTMin.Value;
            ItemSysReq.OutType = ucDrpOutType.selectedText;
            ItemSysReq.NeedBellow = cBoxNeedBellow.Checked;
            ItemSysReq.NeedBreaker = cBoxNeedBreaker.Checked;
            ItemSysReq.NeedFilter = cBoxNeedFilter.Checked;
            ItemSysReq.NeedFlowmeter = cBoxNeedFlowmeter.Checked;
            ItemSysReq.NeedPreGauge = cBoxNeedPreGauge.Checked;
            ItemSysReq.NeedTap = cBoxNeedTap.Checked;
            ItemSysReq.NeedTrap = cBoxNeedTrap.Checked;
            ItemSysReq.NeedValve = cBoxNeedValve.Checked;
            ItemSysReq.Name = textBoxName.Text;
            ItemSysReq.SystemType = cBoxSystemType.SelectedValue.ToString();
            ItemSysReq.Wenduji = cBoxWenduji.Checked;
           
            string jsons = JsonConvert.SerializeObject(ItemSysReq);
            var result = Client.Put(urlSysReq + "Update", jsons);
            if (Utils.ExceptionHandler(result) == null)
            {
                Utils.SysMsg("保存成功！");
                var resp = Utils.SuccessHandler(result);
                ItemSysReq = JsonConvert.DeserializeObject<HKP_ToolSysReqDto>(resp.ToString());
                GetToolSysReq(Item.Id);
            }
        }

        public void GetSystem(string layout, int parentId)
        {
            string url = string.Format("api/services/app/HKP_Category/GetList?layout={0}&parentId={1}", layout, parentId);
           
            var result = Client.Get(url);
            listSystemType = JsonConvert.DeserializeObject<ItemsDto<HKP_CategoryDto>>(result);
            cBoxSystemType.DisplayMember = "cateName";
            cBoxSystemType.ValueMember = "cateName";
            cBoxSystemType.DataSource = listSystemType?.result?.items;
            cBoxSystemType.SelectedIndex = -1;
            cBoxSystemType.SelectionChangeCommitted += CBoxSystemType_SelectedIndexChanged;
        }

        private void CBoxSystemType_SelectedIndexChanged(object sender, EventArgs e)
        {
            cBoxSysNo.DataSource = null;
            string sysNo = cBoxSystemType.SelectedValue.ToString();
            string url = string.Format("api/services/app/HKP_System/GetListSysNo?keywords={0}", sysNo);
            var result = Client.Get(url);
            res1 = JsonConvert.DeserializeObject<ItemsDto<HKP_SystemDto>>(result);
            //赋值给详细下拉
            cBoxSysNo.DisplayMember = "SysNo";
            cBoxSysNo.ValueMember = "SysNo";
            cBoxSysNo.DataSource = res1.result?.items;
            cBoxSysNo.SelectedIndex = -1;
            if (sysNo == "PW")
            {
                ucDrpFlowUnit.Init("PW容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpPressUnit.Init("PW压力", Client.RemoteHost, 0, "kg/cm²");//压力单位
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位
            }
            if (sysNo == "PV")
            {
                ucDrpFlowUnit.Init("PV容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpPressUnit.Init("PV压力", Client.RemoteHost, 0, "mmHg");//压力单位--mmHg
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位
            }

            if (sysNo == "PA")
            {
                ucDrpFlowUnit.Init("PA容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位
            }
            if (sysNo == "PB_PP" || sysNo == "PS")
            {
                ucDrpFlowUnit.Init("PB_PP容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpPressUnit.Init("PW压力", Client.RemoteHost, 0, "kg/cm²");//压力单位
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位
            }
            //化学特殊一点，下面的会变，所以直接控制总大类
            if (sysNo == "PC")
            {
                ucDrpFlowUnit.Init("PS容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpPressUnit.Init("PW压力", Client.RemoteHost, 0, "kg/cm²");//压力单位
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位

                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";

                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Enabled = true;//功率
                ucDrpPowerUnit.Enabled = true;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度

                cBoxNeedValve.Checked = false;
                cBoxNeedValve.Enabled = false;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾

            }
            if (sysNo == "PE")
            {
                ucDrpFlowUnit.Init("PE容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpPressUnit.Init("PE压力", Client.RemoteHost, 0, "Pa");//压力单位--mmHg
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位
            }
            if (sysNo == "PH")
            {
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位
            }
            if (sysNo == "PD")
            {
                ucDrpFlowUnit.Init("PS容量", Client.RemoteHost, 0, "L/min");//容量单位
                ucDrpPressUnit.Init("PW压力", Client.RemoteHost, 0, "kg/cm²");//压力单位
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("PW尺寸", Client.RemoteHost, 0, "in");//尺寸的那位

            }
            if (sysNo == "ES")
            {
                ucDrpFlowUnit.Init("容量", Client.RemoteHost, 0, "A");//容量单位
                ucDrpPressUnit.Init("容量", Client.RemoteHost, 0, "A");//压力单位
                ucDrpPowerUnit.Init("功率", Client.RemoteHost, 0, "KW");//功率单位
                ucDrpOutSizeUnit.Init("电源种类", Client.RemoteHost, 0, "N");//尺寸的那位

            }
        }

       

        private void DataGridViewM_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            SetCurrToolSys();
        }
        private void SetCurrToolSys()
        {
            ItemSysReq = dataGridViewM.CurrentRow.DataBoundItem as HKP_ToolSysReqDto;
         
            if (ItemSysReq != null)
            {
                numFlowPeak.Value = ItemSysReq.FlowPeak;
                numFlowOpr.Value = ItemSysReq.FlowOper;
                numFlowAvg.Value = ItemSysReq.FlowAvg;
                ucDrpFlowUnit.SetText(ItemSysReq.FlowUnit);
                textOutSize.Text = ItemSysReq.OutSize;//接点尺寸
                ucDrpOutSize.SetText(ItemSysReq.OutSize);
                ucDrpOutSizeUnit.SetText(ItemSysReq.OutSizeUnit);
                numPower.Value = ItemSysReq.Power;
                ucDrpPowerUnit.SetText(ItemSysReq.PowerUnit);
                numPressure.Value = ItemSysReq.Pressure;
                ucDrpPressUnit.SetText(ItemSysReq.PressureUnit);
                cBoxSysNo.SelectedValue = ItemSysReq.SysNo;
                numTemperatureWRTMax.Value = ItemSysReq.TemperatureWRTMax;
                numTemperatureWRTMin.Value = ItemSysReq.TemperatureWRTMin;
                cBoxNeedBellow.Checked = ItemSysReq.NeedBellow;
                cBoxNeedBreaker.Checked = ItemSysReq.NeedBreaker;
                cBoxNeedFilter.Checked = ItemSysReq.NeedFilter;
                cBoxNeedFlowmeter.Checked = ItemSysReq.NeedFlowmeter;
                cBoxNeedPreGauge.Checked = ItemSysReq.NeedPreGauge;
                cBoxNeedTap.Checked = ItemSysReq.NeedTap;
                cBoxNeedTrap.Checked = ItemSysReq.NeedTrap;
                cBoxNeedValve.Checked = ItemSysReq.NeedValve;
                cBoxWenduji.Checked = ItemSysReq.Wenduji;//新增温度计

                HKP_CategoryDto[] list = listSystemType.result.items.Where(a => a.CateName == ItemSysReq.SystemType).ToArray();
                if (list.Length > 0)
                {
                    cBoxSystemType.SelectedItem = list[0];
                    string url = string.Format("api/services/app/HKP_System/GetListSysNo?keywords={0}", ItemSysReq.SysNo);
                    var result = Client.Get(url);
                    res1 = JsonConvert.DeserializeObject<ItemsDto<HKP_SystemDto>>(result);
                    HKP_SystemDto[] list1 = res1.result.items.Where(o => o.SysNo == ItemSysReq.SysNo).ToArray();
                    if (list1.Length > 0)
                    {
                        cBoxSysNo.SelectedItem = list1[0];
                    }
                }
                


                textBoxName.Text = ItemSysReq.Name;
                buttonSaveConn.Enabled = true;
                ucDrpOutType.SetText(ItemSysReq.OutType);


            }
        }

        private void AddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ButtonAddConn_Click(sender, e);
        }

        private void DelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Item != null)
            {
                if (Item.songshen == true)
                {
                    Utils.SysMsg("机台已送审，不允许修改，可撤回之后修改！");
                    return;
                }
            }

            ItemSysReq = dataGridViewM.CurrentRow.DataBoundItem as HKP_ToolSysReqDto;

            if (MessageBox.Show("确定删除接口？", "系统", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                if (ItemSysReq != null)
                {
                    string act = string.Format(urlSysReq + "Delete?Id={0}", ItemSysReq.Id);
                    string result = Client.Delete(act);
                    if (Utils.ExceptionHandler(result) == null)
                    {
                        GetToolSysReq(Item.Id);
                    }                    
                }
            }
        }

        private void EditToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetCurrToolSys();
        }




        private void cBoxSysNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            var item = this.cBoxSysNo.SelectedItem as HKP_SystemDto;
            if (item == null)
            {
                return;
            }
            string x = this.cBoxSysNo.SelectedValue.ToString();

            //label36
            if (x == "ES")
            {
                //改变
                this.label23.Text = "负荷";
                this.label24.Text = "设备路断器";
                this.label25.Text = "电压/(V)";
                this.labESType.Text = "电源种类";
                numTemperatureWRTMax.Value = 0;
                numTemperatureWRTMin.Value = 0;


                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Value = 0;
                numPower.Enabled = true;//功率
                
                ucDrpPowerUnit.Enabled = true;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位

                numTemperatureWRTMin.Enabled = false;//最小温度
                numTemperatureWRTMax.Enabled = false;//最高温度

                cBoxNeedValve.Checked = false;
                cBoxNeedValve.Enabled = false;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计

                cBoxNeedBreaker.Enabled = true;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾

            }

            #region PW系统
            //PW系统
            if (x == "PCWR")
            {
             

                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";
            

                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Value = 0;
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度

                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表

                cBoxWenduji.Enabled = true;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀

                cBoxNeedFlowmeter.Enabled = true;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            if (x == "PCWS")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";

                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Value = 0;
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度


                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
 
                cBoxNeedPreGauge.Enabled = true;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计

                cBoxNeedTap.Enabled = true;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            #endregion

            #region PV系统
            if (x == "PV")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";

                numFlowPeak.Enabled = true;//峰值

                numFlowAvg.Enabled = true;//平均

                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位

                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位

                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度



                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            #endregion

            #region PA系统
            //废水系统
            if (x == "W-DIR" || x == "W-AA" || x == "W-ORG" || x == "W-Ni" || x == "W-Ag" || x == "W-Au" || x == "W-Met" || x == "W-Cu(E)" || x == "D-Ni" || x == "D-Ag" || x == "D-Cu" || x == "D-Au" || x == "D-Ti" || x == "D-PI" || x == "D-PR" || x == "D-STR")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";

                numFlowPeak.Value = 0;
                numFlowPeak.Enabled = false;//峰值
                numFlowAvg.Value = 0;
                numFlowAvg.Enabled = false;//平均
                numFlowOpr.Value = 0;
                numFlowOpr.Enabled = false;//操作
                ucDrpFlowUnit.Enabled = false;//流量单位
                numPressure.Value = 0;
                numPressure.Enabled = false;//压力
                ucDrpPressUnit.Enabled = false;//压力单位
                numPower.Value = 0;
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度


                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器

                cBoxNeedTrap.Enabled = true;//存水湾
            }
            #endregion

            #region PB_PP 系统
            //PB_PP
            if (x == "GN2" || x == "CDA" || x == "Ar" || x == "O2")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";
                numTemperatureWRTMax.Value = 0;
                numTemperatureWRTMin.Value = 0;

                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度


                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器

                cBoxNeedPreGauge.Enabled = true;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计

                cBoxNeedTap.Enabled = true;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾

            }
            #endregion

            #region PE 系统
            //PE系统
            if (x == "XGE" || x == "XOG" || x == "XAE" || x=="XAR")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";
                numFlowPeak.Value = 0;
                numFlowPeak.Enabled = false;//峰值
                numFlowAvg.Value = 0;
                numFlowAvg.Enabled = false;//平均
                numFlowOpr.Value = 0;
                numFlowOpr.Enabled = false;//操作
                ucDrpFlowUnit.Enabled = false;//流量单位
                numPressure.Value = 0;
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度

                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器

                cBoxNeedPreGauge.Enabled = true;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            #endregion

            #region PS气体
            //PS气体
            if (x == "4%H2/He" || x == "CO2" || x == "CF4")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";
                numTemperatureWRTMax.Value = 0;
                numTemperatureWRTMin.Value = 0;

                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度

                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器

                cBoxNeedPreGauge.Enabled = true;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计

                cBoxNeedTap.Enabled = true;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            #endregion

            #region PH系统
            //PH
            if (x == "PH")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";

                numFlowPeak.Value = 0;
                numFlowPeak.Enabled = false;//峰值
                numFlowAvg.Value = 0;
                numFlowAvg.Enabled = false;//平均
                numFlowOpr.Value = 0;
                numFlowOpr.Enabled = false;//操作
                ucDrpFlowUnit.Enabled = false;//流量单位
                numPressure.Value = 0;
                numPressure.Enabled = false;//压力
                ucDrpPressUnit.Enabled = false;//压力单位

                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度

                cBoxNeedValve.Checked = false;
                cBoxNeedValve.Enabled = false;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            #endregion

            #region PD系统
            //PD
            if (x == "CDI")
            {
                this.label23.Text = "流量";
                this.label24.Text = "压力";
                this.label25.Text = "接点尺寸";
                this.labESType.Text = "尺寸单位";


                numFlowPeak.Enabled = true;//峰值
                numFlowAvg.Enabled = true;//平均
                numFlowOpr.Enabled = true;//操作
                ucDrpFlowUnit.Enabled = true;//流量单位
                numPressure.Enabled = true;//压力
                ucDrpPressUnit.Enabled = true;//压力单位
                numPower.Enabled = false;//功率
                ucDrpPowerUnit.Enabled = false;//功率单位
                ucDrpOutSize.Enabled = true;//接点尺寸
                ucDrpOutSizeUnit.Enabled = true;//尺寸单位
                numTemperatureWRTMin.Enabled = true;//最小温度
                numTemperatureWRTMax.Enabled = true;//最高温度

                cBoxNeedValve.Enabled = true;//阀门
                cBoxNeedFilter.Checked = false;
                cBoxNeedFilter.Enabled = false;//过滤器
                cBoxNeedBellow.Checked = false;
                cBoxNeedBellow.Enabled = false;//蜂鸣器
                cBoxNeedPreGauge.Checked = false;
                cBoxNeedPreGauge.Enabled = false;//压力表
                cBoxWenduji.Checked = false;
                cBoxWenduji.Enabled = false;//温度计
                cBoxNeedTap.Checked = false;
                cBoxNeedTap.Enabled = false;//调压阀
                cBoxNeedFlowmeter.Checked = false;
                cBoxNeedFlowmeter.Enabled = false;//流量计
                cBoxNeedBreaker.Checked = false;
                cBoxNeedBreaker.Enabled = false;//设备路断器
                cBoxNeedTrap.Checked = false;
                cBoxNeedTrap.Enabled = false;//存水湾
            }
            #endregion

            #region 废水的文本提示
            switch (x)
            {
                //x == "W-DIR" || x == "W-AA" || x == "W-ORG" || x == "W-Ni" || x == "W-Ag" || x == "W-Au" || x == "W-Met" || x == "W-Cu(E)" || x == "D-Ni" || x == "D-Ag" || x == "D-Cu" || x == "D-Au" || x == "D-Ti" || x == "D-PI" || x == "D-PR" || x == "D-STR"
                case "W-DIR":
                    label36.Text = "First rinse/final rinse/ temp. adjustment/ condensed water/ wafer particle rinse";
                    break;
                case "W-AA":
                    label36.Text = "酸碱废水，清洗化学品之排水，非有机类及重金属类排水，不允许高浓度废液排入";
                    break;
                case "W-ORG":
                    label36.Text = "有机废水，清洗有机溶剂之排水，不允许高浓度溶剂排入< 注意 > 四甲基氢氧化铵(TMAH, C4H13NO)低濃度2.35 % 顯影液排入此股廢水處理";
                    break;
                case "W-Ni":
                    label36.Text = "含镍废水, 清洗高含镍化学品之排水，不允许高浓度含镍化学品排入";
                    break;
                case "W-Ag":
                    label36.Text = "含银废水, 清洗高含银化学品之排水，不允许高浓度含银化学品排入";
                    break;
                case "W-Au":
                    label36.Text = "含金废水,清洗高含金化学品之排水，不允许高浓度含金化学品排入";
                    break;
                case "W-Met":
                    label36.Text = "其他金属废水，非镍、银、金类废水，含其他金属的清洗排水";
                    break;
                case "W-Cu(E)":
                    label36.Text = "含铜蚀刻废水，清洗铜蚀刻化学品之排水，不允许高浓度蚀刻液排入";
                    break;
                case "D-Ni":
                    label36.Text = "只允许高浓度镍电镀废液排入";
                    break;
                case "D-Ag":
                    label36.Text = "只允许高浓度银、锡化银电镀废液排入";
                    break;
                case "D-Cu":
                    label36.Text = "只允许高浓度铜电镀&铜蚀刻废液排入";
                    break;
                case "D-Au":
                    label36.Text = "只允许高浓度金电镀废液排入";
                    break;
                case "D-Ti":
                    label36.Text = "只允许高浓度钛蚀刻废液排入";
                    break;
                case "D-PI":
                    label36.Text = "只允许高浓度PI类光阻类废液收集(PI, dilution agent etc.)ex.PI光刻胶、PI显影液(环戊酮、丙二醇单甲醚乙酸酯)";
                    break;
                case "D-PR":
                    label36.Text = "只允许高浓度PR类光阻类废液收集(PR, dilution agent etc.)";
                    break;
                case "D-STR":
                    label36.Text = "只允许高浓度Stripper类废液收集 ex.三乙醇胺 + 二甘醇乙醚 + N-甲基吡咯烷酮";
                    break;

                default:
                    label36.Text = "";
                    break;
            }

            #endregion
        }
    }
}
